#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
	char ch[300] = { 0 };
	char x1 = 0;
	char x2 = 0;
	int a = 0;
	int b = 0;
	int c = 0;
	while (scanf("%c:=%c;", &x1, &x2) == 2)
	{
		{
			if (x1 == 'a')
			{
				if (x2 == 'a')
					a = a;
				else if (x2 == 'b')
					a = b;
				else if (x2 == 'c')
					a = c;
				else
					a = x2 - '0';
			}
			if (x1 == 'b')
			{
				if (x2 == 'a')
					b = a;
				else if (x2 == 'b')
					b = b;
				else if (x2 == 'c')
					b = c;
				else
					b = x2 - '0';
			}
			if (x1 == 'c')
			{
				if (x2 == 'a')
					c = a;
				else if (x2 == 'b')
					c = b;
				else if (x2 == 'c')
					c = c;
				else
					c = x2 - '0';
			}
		}
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}
